package com.servlet.response; /**
 * @author wzm
 * @create 2023-11-06 11:26
 * project_name:web2310
 * @Description
 */

import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;

@WebServlet("/resp5")
public class ResponseServlet5 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doPost(request, response);//调用doPost
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      //响应字节数据 响应一个图片到浏览器

        //1.从磁盘上读取一个图片 输入流
        FileInputStream fis = new FileInputStream("D://jd.jpg");//88888895154

        //2. 获取字节输出流
        ServletOutputStream os = response.getOutputStream();

        //3.将输入流数据读取到输出中进行输出
        IOUtils.copy(fis,os);//输入流复制到输出流中

        //关闭流 自己创建的需要关闭 response对象不需要管
        fis.close();

    }
}
